<?php

if (!isset($_SESSION)) {
    session_start();
}

class package extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     * 		http://example.com/index.php/welcome
     * 	- or -  
     * 		http://example.com/index.php/welcome/index
     * 	- or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    protected $configs;

    function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->library('smarty3', '', 'smarty');
        $this->load->model('pushclimb/product_model', 'product_model');
        $this->load->model('pushclimb/package_model', 'package_model');
        $this->load->model('admin-planners/setting_model', 'setting_model');
        include APPPATH . 'libraries/defu.php';
    }

    function Init() {
        $data = $this->setting_model->gets();
        foreach ($data as $v) {
            $_SESSION["SETTINGS"][$v->Key] = $v->Value;
        }
    }

    public function index() {
        show_404();
    }

    public function detail($alias = "") {
        $Data = null;

        
        $obj = $this->package_model->getByAlias($alias);
        if (count($obj) > 0) {
            $Data["OBJ"] = $obj[0];
            
            $tmp = $this->setting_model->getByKey("mad-rock-products");
            $Data["mad-rock-products"]= $tmp[0];

            $tmp = $this->setting_model->getByKey("how-to-buy");
            $Data["how-to-buy"]= $tmp[0];

            $detail = json_decode($Data["OBJ"]->Detail, true);
            $lst = array();
            $tmp = array();
            foreach ($detail as $pr) {
                $lst[] = $pr[0];
                $tmp[$pr[0]] = $pr[1];
            }
            $Data["OBJ"]->Detail = $tmp;
            $Data["tmp"]=$tmp;
            $products = $this->product_model->getIn($lst);
            $Data["Products"] = $products;
            
        }else            show_404 ();
        $Data["Packages"]=$this->package_model->gets();
        $this->smarty
                ->assign('_SESSION', $_SESSION)
                ->assign('Data', $Data)
                ->display("pushclimbing/pages/05_package");
    }

}
